package com.example.customview.head_hover

import com.alibaba.android.arouter.facade.annotation.Route
import com.android.baselibrary.base.BaseDBFragment
import com.example.customview.R
import com.example.customview.arouter.CustomArouter
import com.example.customview.databinding.FragmentHeadHoverBinding
import com.google.android.material.tabs.TabLayoutMediator

/**
 * 列表头部悬停
 */
@Route(path = CustomArouter.CUSTOM_HEAD_HOVER_FRAGMENT)
class HeadHoverFragment  :BaseDBFragment<FragmentHeadHoverBinding>(R.layout.fragment_head_hover){
    private val tabs by lazy {
       listOf( "新闻","财经","流行","故事","听书","歌曲")
    }
    private val fragments by lazy {
        listOf(
            ChildFragment(),
            ChildFragment(),
            ChildFragment(),
            ChildFragment(),
            ChildFragment(),
            ChildFragment()
        )
    }
    override fun initView() {
       mBinding.viewPage.adapter = activity?.let {
           HeadHoverPageFragmentAdapter(it, fragments)
       }
        TabLayoutMediator(mBinding.tabLayout,mBinding.viewPage
        ) { tab, position -> tab.text = tabs[position] }.attach()

        mBinding.llHead.post {
            mBinding.llHead.layoutParams.height =
                mBinding.nestedscrollview.measuredHeight
            mBinding.llHead.requestLayout()
        }
    }
}